//
//  MoodViewController.m
//  Travel assistant
//
//  Created by lanou3g on 16/3/7.
//  Copyright © 2016年 旅游助手. All rights reserved.
//

#import "MoodViewController.h"

@interface MoodViewController ()<UITextViewDelegate, UITextFieldDelegate>
@property (nonatomic, strong) HMTextView *textView;
@property (nonatomic, strong) UIImagePickerController *imagePicker;
@property (nonatomic, strong) TravelDiaryModel *travelDiaryModel;



@end

@implementation MoodViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setViews];
    [self setDelegate];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.view.backgroundColor = [UIColor whiteColor];
    /**成为第一响应者（呼叫键盘）*/
    [self.textView becomeFirstResponder];
}
- (void)setViews{
    self.textView = [[HMTextView alloc] init];
    /**垂直向上拥有弹簧效果*/
    self.textView.alwaysBounceVertical = YES;
    self.textView.frame = CGRectMake(8, 8, Screen_W - 16, 250);
    /**placeholder*/
    self.textView.placehoder = @"将自己的心情描绘下来吧......";
    /**字体*/
    self.textView.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:self.textView];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"correct_31.883720930233px_1163714_easyicon.net"] style:UIBarButtonItemStyleDone target:self action:@selector(rightBarButtonItemAction:)];
    
}
- (void)rightBarButtonItemAction:(UIBarButtonItem *)sender{
    
    self.travelDiaryModel = [TravelDiaryModel object];
    [self.travelDiaryModel setObject:self.textView.text forKey:@"notesText"];
    [self.travelDiaryModel setObject:[NSString stringWithFormat:@"text"] forKey:@"notesType"];
    [self.travelDiaryModel saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"self.travelDiaryModel存储成功....");
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            NSLog(@"%@",error);
        }
    }];
    
}
/**换行回收键盘*/
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([@"\n" isEqualToString:text]) {
        [self.textView resignFirstResponder];
        return NO;
    }
    return YES;
}
- (void)setDelegate{
    self.textView.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
